<template>
  <div class="login_contanier">
    <div class="box">
      <div class="top">
        <img src="../assets/logo.png" alt="" />
      </div>
      <!-- 表单 -->
      <el-form ref="loginform" :model="loginform" label-width="80px" :rules="loginrules">
        <el-form-item label="账号" prop="username">
          <el-input v-model="loginform.username" prefix-icon="el-icon-user-solid"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="loginform.password" prefix-icon="iconfont icon-3702mima"></el-input>
        </el-form-item>
        <div class="botton_btn">
           <el-button @click="reset">重置</el-button>
           <el-button type="primary" @click="submit">提交</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        datalist: '',
        loginform: {
          username: 'admin',
          password: '123456'
        },
        loginrules: {
          username: [{
              required: true,
              message: '请输入账号',
              trigger: 'blur'
            },
            {
              min: 3,
              max: 5,
              message: '长度在 3 到 5 个字符',
              trigger: 'blur'
            }
          ],
          password: [{
              required: true,
              message: '请输入密码',
              trigger: 'blur'
            },
            {
              min: 6,
              max: 12,
              message: '长度在 6 到 12 个字符',
              trigger: 'blur'
            }
          ]
        }
      }
    },
    methods: {
      // 这是重置账号和密码
      reset() {
        this.$refs.loginform.resetFields()
      },
      // 这是提交
      submit() {
        // 提交前进行表单预验证
        this.$refs.loginform.validate(validate => {
          if (!validate) {
            return this.$message.error('请输入正确的信息')
          }
          // 验证成功的表现
          this.$router.push('/home')
        })
      }
    }
  }

</script>

<style lang="less" scoped>
  .login_contanier {
    height: 100%;
    background-color: skyblue;

    .box {
      position: absolute;
      width: 600px;
      height: 300px;
      background-color: #fff;
      border-radius: 10px;
      box-sizing: border-box;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);

      .top {
        position: absolute;
        width: 130px;
        height: 130px;
        border: 1px solid #ccc;
        border-radius: 50%;
        overflow: hidden;
        background-color: #ccc;
        box-shadow: 0 0 10px #ccc;
        left: 50%;
        transform: translate(-50%, -50%);

        img {
          width: 100%;
          height: 100%;
        }
      }
    }

    .el-form {
      margin-top: 80px;
      padding: 30px;
    }
    .botton_btn {
      display: flex;
      justify-content: flex-end;
    }
  }

</style>
